#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner
{
    #region ParticleEmitterRocketSmoke class
    public partial class ParticleEmitterRocketSmoke : ParticleEmitterBase
    {
        public ParticleEmitterRocketSmoke()
        {

        }

        protected override Particle OnCreateParticle(int nParticleCount, int nParticleIndex)
        {
            Random rnd = new Random();
            int nDeg = rnd.Next(360);

            return new Particle(Position,
                                  new Vector3((float)Math.Sin(MathHelper.ToRadians(nDeg)), (float)Math.Cos(MathHelper.ToRadians(nDeg)), 0.0f),
                                  m_currConfig.ParticleLife,
                                  m_currConfig.ParticleSpeed,
                                  m_currConfig.ParticleSize,
                                  new Vector4(0.9f, 0.9f, 0.9f, 1.0f));
        }

        protected override bool OnBeforeDrawParticle(int nParticleCount, int nParticleIndex, Particle pParticleToDraw)
        {
            pParticleToDraw.Size *= 1.02f; // (nParticleCount - nParticleIndex + 1) * 0.5f;
            return true;
        }
    }
    #endregion

    #region ParticleEmitterExplosion class
    public class ParticleEmitterExplosion : ParticleEmitterBase
    {
        float m_fHalfLife;
        Vector4 m_vStartColor = new Vector4(1.0f, 1.0f, 0.0f, 1.0f);
        Vector4 m_vMidColor = new Vector4(0.5f, 0.0f, 0.0f, 1.0f);
        Vector4 m_vEndColor = new Vector4(0.1f, 0.0f, 0.0f, 1.0f);

        public ParticleEmitterExplosion()
        {

        }

        protected override Particle OnCreateParticle(int nParticleCount, int nParticleIndex)
        {
            Random rnd = new Random();
            int nDeg = rnd.Next(360);

            m_fHalfLife = m_currConfig.ParticleLife * 0.5f;

            return new Particle(Position,
                                  new Vector3((float)Math.Sin(MathHelper.ToRadians(nDeg)), (float)Math.Cos(MathHelper.ToRadians(nDeg)), 0.0f),
                                  m_currConfig.ParticleLife,
                                  m_currConfig.ParticleSpeed,
                                  m_currConfig.ParticleSize,
                                  new Vector4(0.5f, 0.5f, 0.5f, 1.0f));
        }

        protected override bool OnBeforeDrawParticle(int nParticleCount, int nParticleIndex, Particle pParticleToDraw)
        {
            if (pParticleToDraw.Life > m_fHalfLife)
                pParticleToDraw.Color = Vector4.Lerp(m_vStartColor, m_vMidColor, 1.0f - ((pParticleToDraw.Life - m_fHalfLife) / m_fHalfLife));
            else
                pParticleToDraw.Color = Vector4.Lerp(m_vMidColor, m_vEndColor, 1.0f - (pParticleToDraw.Life / m_fHalfLife));
            return true;
        }
    }
    #endregion

    #region ParticleEmitterFireCircle class
    public class ParticleEmitterFireCircle : ParticleEmitterBase
    {
        float m_fRotation;
        Vector3 m_vRotationPosition = new Vector3();

        public ParticleEmitterFireCircle()
        {
            m_fRotation = 0.0f;
        }

        protected override Particle OnCreateParticle(int nParticleCount, int nParticleIndex)
        {
            m_vRotationPosition.X = Position.X + 2.0f * (float)Math.Sin(m_fRotation);
            m_vRotationPosition.Y = Position.Y + 2.0f * (float)Math.Cos(m_fRotation);
            m_vRotationPosition.Z = Position.Z;

            m_fRotation += 0.1f;

            return new Particle(m_vRotationPosition,
                                Vector3.UnitY,
                                m_currConfig.ParticleLife,
                                m_currConfig.ParticleSpeed,
                                m_currConfig.ParticleSize,
                                new Vector4(0.5f, 0.5f, 0.5f, 1.0f));
        }

        protected override bool OnBeforeDrawParticle(int nParticleCount, int nParticleIndex, Particle pParticleToDraw)
        {
            return true;
        }
    }
    #endregion
}
